<script type="text/javascript">
    var LANG = '<?=LANG?>';
    var THEME = '<?=THEME?>';
    var TEMPLATE = '<?=TEMPLATE?>';
    var url = '/json/<?=TEMPLATE?>/<?=$params[0]?>,<?=$params[1]?>,<?=$params[2]?>';
    var lang = ({
            'file_selected':'<?=uygulama::translate("file/files selected.")?>',
            'start_upload':'<?=sprintf(uygulama::translate("%s click here %s to start upload."),"<u>","</u>")?>',
            'thumbnail':'<?=uygulama::translate("Thumbnail")?>',
            'original_size':'<?=uygulama::translate("Orginal size")?>',
            'left':'<?=uygulama::translate("Left")?>',
            'right':'<?=uygulama::translate("Right")?>',
            'none':'<?=uygulama::translate("None")?>',
            'add':'<?=uygulama::translate("ADD")?>',
            'delete':'<?=uygulama::translate("Delete")?>',
            'edit':'<?=uygulama::translate("Edit")?>',
            'delete_image':'<?=uygulama::translate("Delete Image")?>',
            'are_you_sure':'<?=uygulama::translate("Are you sure delete the imege?")?>'
        });
</script>
<div id="content">
<?if($params[2]):?>
<form id="form" method="POST" action="/json/<?=TEMPLATE.'/'.$params[0].','.$params[1].','.$params[2]?>">
<div class="formItem">
<label><?=uygulama::translate('Title')?>:</label>
<input id="title" name="title" class="wide" type="text" value="<?=$page->subpage->$lang->title?>" />
<span class="clear"></span>
</div>
<div class="formItem">
<label><?=uygulama::translate('Description')?>:</label>
<input id="description" name="description" class="wide" type="text" value="<?=$page->subpage->$lang->description?>" />
<span class="clear"></span>
</div>
<div class="formItem">
<label><?=uygulama::translate('Keywords')?>:</label>
<input id="keywords" name="keywords" class="wide" type="text" value="<?=$page->subpage->$lang->keywords?>" />
<span class="clear"></span>
</div>
<!-- MEDIA -->
<div class="formItem">
<label class="formLabel"><?=uygulama::translate('Media')?>:</label>
<div class="uploader">
    <object id="mediaUploader" type="application/x-shockwave-flash" data="/lib/f4/uploader.swf" width="80" height="26">
        <param name="movie" value="/lib/f4/uploader.swf" />
        <param name="quality" value="high" />
        <param name="wmode" value="window" />
        <param name="allowScriptAccess" value="sameDomain" />
        <param name="flashVars" value="callback=mediaUploader
                &uploadurl=/upload/<?=TOKEN?>/<?=$params[0]?>,<?=$params[1]?>,<?=$params[2]?>
                &filetypes=*.jpeg;*.jpg;*.gif;*.png;
                &typetext=Media (.jpeg;.jpg;.gif;.png;)
                &labeltext=<?=uygulama::translate('Browse')?>
                &fontcolor=#ffffff
                &bgcolor=0x111111
                &autoupload=1"/>
    </object>
    <span id="uploaderdesc" class="uploaderLabel"><?=uygulama::translate('Select images')?></span>
    </div>
    <div class="clear"></div>
</div>
<div id="mediaContainer">
    <?if($page->subpage->media) foreach($page->subpage->media as $k=>$i):?>
    <div id="<?=$k?>" class="media">
        <div class="thumb">
            <img src="/<?=$i->thumb?>" alt="<?=$i->alt?>" />
        </div>
        <div data-id="<?=$k?>" class="name inlineedit" data-url="/json/<?=TEMPLATE?>/<?=$params[0]?>,<?=$params[1]?>,<?=$params[2]?>,alt"><?=$i->alt?></div>
        <a class="button remove" onclick="mediaRemove('<?=$k?>');">x</a>
    </div>
    <?endforeach;?>
</div>
<div class="clear"></div>
<!-- SUBMIT -->
<div class="formSubmit">
<span id="loader" class="loader"><img src="/themes/<?=THEME?>/images/loader.gif" alt="loader" /></span>
<input type="submit" value="<?=uygulama::translate('Save')?>" />
</div>
</form>
<script type="text/javascript">
tool.sortable('mediaContainer','img',{'url':'/json/<?=TEMPLATE?>/<?=$params[0].','.$params[1].','.$params[2].',sort'?>'});
tool.inlineedits();
tool.form(); 
</script>
<?endif;?>
</div>



<div id="aside">
	<h3><?=uygulama::translate('Add New Album')?></h3>
	<div class="formItem">
		<input id="subpage" class="valuelabel" name="subpage" type="text" value="<?=uygulama::translate('write a album title...')?>" /> 
		<a id="subpagepost" href="javascript:newsub();" title="Add new" class="button"><?=_('[+] Add')?></a>
	<div class="clear"></div>
	</div>
	<div class="clear"></div>
	<h3><?=uygulama::translate('Albums')?>:</h3>	
	<div id="subnavForm">
	<? if($page->page->subpages) foreach ($page->page->subpages as $k=>$i): ?> 
	<div id="<?=$k?>" class="formItem">
	<a class="button right" href="javascript:del('<?=$k?>');"><?=uygulama::translate('Delete')?></a>
	<a class="button right" href="/admin/page,<?=$params[1]?>,<?=$k?>"><?=uygulama::translate('Edit')?></a>
	<span class="handler left">::</span>
	<label><?=$i->$lang->title?></label>
	<div class="clear"></div>
	</div>	
	<? endforeach; ?>
	</div>
</div>
<script type="text/javascript">
tool.valuelabels();
var linksort = tool.sortable('subnavForm','span',{'url':'/json/<?=TEMPLATE?>/<?=$params[0].",".$params[1].",sort"?>'});
function add(urn, title){
    var item = $('<div>',{'id':urn,'class':'formItem'})
        .append($('<a>',{'class':'button right','href':'javascript:del(\''+urn+'\')'}).html(lang.delete))
        .append($('<a>',{'class':'button right','href':'/<?=TEMPLATE?>/<?=$params[0]?>,<?=$params[1]?>,'+urn}).html(lang.edit))
        .append($('<span>',{'class':'handler left'}).html('::'))
        .append($('<label>',{'class':'block'}).html(title))
        .append($('<div>',{'class':'clear'}));
    $('#subnavForm').append(item)
}
function del(urn){
    var func = 'tool.post({\'url\':\'/json/<?=TEMPLATE?>/<?=$params[0].",".$params[1].",del"?>\',\'data\':\'urn='+urn+'\',\'onComplete\':function(r){'
            +'if(r.code == 200) $(\'#'+urn+'\').remove(); '
            +'else tool.result(r.code,r.status,r.message,r.fields,r.redirect,r.debug);'
        +'}'
    +'});';
    tool.confirm('Delete Page', 'Are you sure delete the page? You are lose all data!', func);
}
function newsub(){
    var subpageurn = urn($('#subpage').val());
    $('#subpagepost').attr('disabled','disabled');
    tool.post({'url':'/json/<?=TEMPLATE?>/<?=$params[0].",".$params[1].",add"?>',
        'data':'urn='+subpageurn+'&lang='+LANG+'&title='+$('#subpage').val(),
        'onComplete':function(r){
            if(r.code == 200) add(subpageurn, $('#subpage').val());
            else tool.result(r.code,r.status,r.message,r.fields,r.redirect,r.debug);
            $('#subpagepost').removeAttr('disabled');
            $('#subpage').val($('#subpage').attr('data-label')).focus();
        }
    });
}
$('#subpage').keydown(function(e){
    if((e.keyCode == 13) && $('#subpage').val() && $('#subpage').val() != $('#subpage').attr('data-value')) { // enter
        if(e) e.preventDefault();
        newsub();
    } return true;
});
    var projecttitle = ('<?=TITLE?>'.length+3);
    $('#title').keyup(function(){
        tool.lengthcheck('title',5,70-projecttitle);
    });
    tool.lengthcheck('title',5,70-projecttitle);
    $('#description').keyup(function(){
        tool.lengthcheck('description',70,120);
    });
    tool.lengthcheck('description',70,120);
</script>